home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Dots & Pixels / sources / stereopair.cp < prev    next >
Text File  |  1995-09-29  |  3KB  |  124 lines

  1. #include <stdlib.h>
  2.  
  3. #include <Windows.h>
  4. #include <QDOffscreen.h>
  5. #include <Memory.h>
  6. #include <Fonts.h>
  7. #include <Packages.h>
  8. #include <SegLoad.h>
  9. #include <ToolUtils.h>
  10. #include <TextEdit.h>
  11. #include <Files.h>
  12.  
  13. #include "C_randomizer.h"
  14.  
  15. #include "general.h"
  16. #include "port.h"
  17. #include "gworld.h"
  18. #include "stereopair.h"
  19.  
  20. stereopair::stereopair( int breedte, int hoogte,
  21.                 int backDisparity, CTabHandle cTable)
  22. {
  23.     my_leftDisparity  = backDisparity / 2;
  24.     my_rightDisparity = my_leftDisparity - backDisparity;
  25.  
  26.     L  = new gworld( breedte, hoogte, 1);
  27.     R  = new gworld( breedte, hoogte, 1);
  28.     LR = new gworld( breedte, hoogte, 2, cTable);
  29.  
  30.     if( my_leftDisparity != 0)
  31.     {
  32.         left_noise  = new gworld( abs( my_leftDisparity), hoogte, 1);
  33.     } else {
  34.         left_noise = 0;
  35.     }
  36.     if( my_rightDisparity != 0)
  37.     {
  38.         right_noise = new gworld( abs( my_rightDisparity), hoogte, 1);
  39.     } else {
  40.         right_noise = 0;
  41.     }
  42.     leftNoiseRect.top    = 0;
  43.     leftNoiseRect.left   = 0;
  44.     leftNoiseRect.bottom = hoogte;
  45.     leftNoiseRect.right  = abs( my_leftDisparity);
  46.  
  47.     leftNoiseImageRect = leftNoiseRect;
  48.  
  49.     rightNoiseRect.top    = 0;
  50.     rightNoiseRect.left   = 0;
  51.     rightNoiseRect.bottom = hoogte;
  52.     rightNoiseRect.right  = abs( my_rightDisparity);
  53.     
  54.     rightNoiseImageRect = rightNoiseRect;
  55.     
  56.     if( my_leftDisparity < 0)
  57.     {
  58.         OffsetRect( &leftNoiseImageRect, breedte + my_leftDisparity, 0);
  59.     }
  60.     if( my_rightDisparity < 0)
  61.     {
  62.         OffsetRect( &rightNoiseImageRect, breedte + my_rightDisparity, 0);
  63.     }
  64. }
  65.  
  66. stereopair::~stereopair()
  67. {
  68.     delete L;
  69.     delete R;
  70.     if( left_noise != 0)
  71.     {
  72.         delete left_noise;
  73.     }
  74.     if( right_noise != 0)
  75.     {
  76.         delete right_noise;
  77.     }
  78.     delete LR;
  79. }
  80.  
  81. void stereopair::CleanSheet() const
  82. {
  83.     L->fill_random();
  84.     R->copyfrom( *L);
  85.     L->scroll( my_leftDisparity,  0);
  86.     R->scroll( my_rightDisparity, 0);
  87.     //
  88.     // fill in the 'exposed parts' of the rectangles with new random noise:
  89.     //
  90.     if( left_noise != 0)
  91.     {
  92.         left_noise->fill_random();
  93.         L->copyfrom( *left_noise, leftNoiseRect, leftNoiseImageRect);
  94.     }
  95.     if( right_noise != 0)
  96.     {
  97.         right_noise->fill_random();
  98.         R->copyfrom( *right_noise, rightNoiseRect, rightNoiseImageRect);
  99.     }
  100. }
  101.     
  102. void stereopair::AddRect( short x, short y, short width, short height,
  103.                     int leftDisparity, int rightDisparity) const
  104. {
  105.     gworld newNoise( width, height, 1);
  106.     newNoise.fill_random();
  107.  
  108.     const short leftX  = x + leftDisparity;
  109.     const short rightX = x + rightDisparity;
  110.     
  111.     const Rect noiseRect = {0, 0, height, width};
  112.     const Rect leftRect  = {y, leftX,  y + height, leftX  + width};
  113.     const Rect rightRect = {y, rightX, y + height, rightX + width};
  114.     
  115.     L->copyfrom( newNoise, noiseRect, leftRect);
  116.     R->copyfrom( newNoise, noiseRect, rightRect);
  117. }
  118.  
  119. const gworld *stereopair::GetImage() const
  120. {
  121.     LR->two_bit_merge( *L, *R);
  122.     return LR;
  123. }
  124.